﻿using BaseData.API.Read.Applications.Commands;
using BaseData.Domain;
using BaseData.ErrorCode;
using BaseData.Infrastructure.Interfaces;
using MediatR;

namespace BaseData.API.Read.Applications.CommandHandlers
{
    /// <summary>
    /// 绑定权限--命令
    /// </summary>
    public class BindPermissionCommandHandler : IRequestHandler<BindPermissionCommand, ApiResult<List<Permission>>>
    {
        private readonly IBaseRepository<Permission> permissionRep;

        public BindPermissionCommandHandler(IBaseRepository<Permission> permissionRep)
        {
            this.permissionRep = permissionRep;
        }
        public Task<ApiResult<List<Permission>>> Handle(BindPermissionCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Permission>> result=new ApiResult<List<Permission>>();
            result.Code=ApiEnum.查询成功;
            result.Message=ApiEnum.查询成功.ToString();

            var list = permissionRep.GetAll().Where(x=>!x.IsDel).ToList();
            result.Data = list;

            return Task.FromResult(result);
        }
    }
}
